<?php

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
#	FILE:			includes/custom/quickupload.php
#	FUNCTION:		Custom handler for the Quick Upload page
#	AUTHOR:			Cameron Morrow
#	CREATED:		02/03/2006
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Check for added file
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if ($_FILES) {
	
	# Get file name
	$uploaddir = "../assets/uploads/";
	$uploadfile = $uploaddir . basename($_FILES["uploadfile"]["name"]);
	
	# Move to upload directory
	if (@move_uploaded_file($_FILES["uploadfile"]["tmp_name"], $uploadfile)) {

		# Was thumbnail created?
		$thumbnail_created = false;

		# Extension
		$extension = substr($_FILES["uploadfile"]["name"], strrpos($_FILES["uploadfile"]["name"], ".") + 1);

		# Check if JPG
		if ($extension == "jpg" || $extension == "jpeg") {

			# Check if creating thumbnail
			if (@$_POST["createthumbnail"]) {

				# Create Thumbnail
				if (createThumbnail($uploaddir, $_FILES["uploadfile"]["name"])) {
					addMessage("<p>Thumbnail was created successfully.</p>");
					$thumbnail_created = true;
				} else {
					addMessage("<p>Sorry, a thumbnail could not be created.</p>", 2);
				}
			}
		}

		# Message
		addMessage("<p>OK, file <em>" . $_FILES["uploadfile"]["name"] . "</em> was added to the uploads directory.</p>");

		# Log
		addLog(basename($_FILES["uploadfile"]["name"]) . "|" . ($thumbnail_created ? "true" : "false"), 17);

	} else {

		# Message
		addMessage("<p>Sorry, an error occured while uploading the file. Please try uploading the file again.</p>", 2);

	}
}


# Add file form
addContent("" .
	"<p>Select the file to be added, then click \"Add File\" to upload it:</p>" .
	"<form name=\"addfileform\" id=\"addfileform\" action=\"" . $PAGE_ID . ".php\" enctype=\"multipart/form-data\" method=\"post\">" .
	"<p>File: <input type=\"file\" size=\"30\" name=\"uploadfile\" id=\"uploadfile\" /><br /><input type=\"checkbox\" id=\"createthumbnail\" name=\"createthumbnail\" /> <label for=\"createthumbnail\">Create thumbnail (for JPG only)</label></p>" .
	"<p><input type=\"submit\" value=\"Add File\" /> <input type=\"button\" value=\"Cancel\" onclick=\"window.close();\" /></p>" .
	"</form>");


?>